package cn.com.se.多线程.excel;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;

import java.security.SecureRandom;
import java.util.*;

/**
 * @Description TODO
 * @Author:lingheng
 * @Date:2022-09-29 11:05
 * @Version 1.0
 **/
public class Test {

    public static Map<String, String> initMap = new HashMap<>();


    public static void main(String[] args) {
        ExcelReader reader = ExcelUtil.getReader("E:/data.xlsx");
        List<Map<String, Object>> readAll = reader.readAll();
        List<String> list = new ArrayList<>();
        readAll.forEach(map -> {
            String code = map.get("*岗位编码").toString();
            if (initMap.containsKey(code)) {

                String radm = Test.getPickupCode(list);

                System.out.println(
                        map.get("*岗位编码") + radm + "," +
                                map.get("*岗位名称") + "," +
                                map.get("设立日期") + "," +
                                map.get("所属部门编码") + "," +
                                map.get("岗位类别") + "," +
                                map.get("*最低职级") + "," +
                                map.get("*最高职级") + "," +
                                map.get("*关键岗位") + "," +
                                map.get("*专业序列") + "," +
                                map.get("*岗位序列") + "," +
                                map.get("*岗位属性") + "," +
                                map.get("*是否大单品岗责"));
            } else {
                System.out.println(
                        map.get("*岗位编码") + "," +
                                map.get("*岗位名称") + "," +
                                map.get("设立日期") + "," +
                                map.get("所属部门编码") + "," +
                                map.get("岗位类别") + "," +
                                map.get("*最低职级") + "," +
                                map.get("*最高职级") + "," +
                                map.get("*关键岗位") + "," +
                                map.get("*专业序列") + "," +
                                map.get("*岗位序列") + "," +
                                map.get("*岗位属性") + "," +
                                map.get("*是否大单品岗责"));
            }

            initMap.put(code, "");
        });


    }

    private static final String SYMBOLS = "0123456789"; // 纯数字
    //如果需加入字母就改成0123456789abcdefg...........

    private static final Random RANDOM = new SecureRandom();


    /**
     * 获取长度为 6 的随机数字
     *
     * @return 随机数字
     */
    public static String getSixstr() {
        char[] nonceChars = new char[5];  //指定长度，自己可以设置

        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars);
    }

    /**
     * 获取数组不存在的6位数取件码
     *
     * @return
     */
    private static String getPickupCode(List<String> list) {
        String sixstr = Test.getSixstr();
        boolean contains = list.contains(sixstr);
        if (contains || sixstr.length() != 5) {
            sixstr = getPickupCode(list);
        }
        return sixstr;
    }
/*
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        //随机生成10万个6位不重复随机数
        for (int i = 0; i < 10000; i++) {
            String pickupCode = Test.getPickupCode(list);
            list.add(pickupCode);
            System.out.println(list.get(i));
        }
        //检查一下是否重复
        Map<String, String> map = new HashMap<>();
        for (String s : list) {
            map.put(s, s);
        }
        System.out.println("list集合大小：" + list.size());
        System.out.println("map集合大小：" + map.size());
        if (list.size() == map.size()) {
            System.out.println("没有重复值");
        } else {
            System.out.println("有重复值");
        }
    }*/

}